package jumavidesktop.GUI.Mantenimientos.Camaras.Vistas;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;
import jumavidesktop.Otros.Pojos.MyRespuesta;
import jumavidesktop.Persistencia.entidades.Camara;
import jumavidesktop.Persistencia.entidades.Configanpr;
import jumavidesktop.Persistencia.entidades.Configdetectionmotion;
import jumavidesktop.Persistencia.entidades.EnumeracionesEntidades.TipoCamara;
import jumavidesktop.Persistencia.entidades.EnumeracionesEntidades.TipoRecursoMotion;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author vimso
 */
public class PanelCamara extends javax.swing.JPanel {
    
    private JPanel jPanel1 = new JPanel();
    private JButton jButton1 = new JButton();
    private String recusoVideo;

    /**
     * Creates new form PanelCamara
     */
    public PanelCamara() {
        initComponents();
        this.refrescarLabelSlider();
        this.setVisible(true);
    }

    public MyRespuesta puedeGuardar() {
        MyRespuesta respuesta = new MyRespuesta();
        if (!(this.jrAmbas.isSelected() || this.jrEntrada.isSelected() || this.jrSalida.isSelected())) {
            respuesta.addError("Debe espcificar la función de la camara");
        }

        if (!(this.jrURL.isSelected() || this.jrVideo.isSelected())) {
            respuesta.addError("Debe especificar el tipo de fuente de video");
        }

        if (StringUtils.isBlank(this.recusoVideo)) {
            respuesta.addError("Debe especificar la ruta de la fuente de video");
        }

        if (StringUtils.isBlank(this.jtNombre.getText())) {
            respuesta.addError("Debe especificar el nombre de la camara");
        }
        return respuesta;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        gbFuncionalidad = new javax.swing.ButtonGroup();
        gbTipoRecurso = new javax.swing.ButtonGroup();
        jfFicheroVideo = new javax.swing.JFileChooser();
        pnCamara = new javax.swing.JPanel();
        jlNombre = new javax.swing.JLabel();
        jtNombre = new javax.swing.JTextField();
        jDescripcion = new javax.swing.JLabel();
        pnFuncionalidadCamara = new javax.swing.JPanel();
        jrEntrada = new javax.swing.JRadioButton();
        jrSalida = new javax.swing.JRadioButton();
        jrAmbas = new javax.swing.JRadioButton();
        jtDescripcion = new javax.swing.JTextArea();
        pnMotion = new javax.swing.JPanel();
        pnTipoRecurso = new javax.swing.JPanel();
        jrVideo = new javax.swing.JRadioButton();
        jrURL = new javax.swing.JRadioButton();
        pnFicheroVideo = new javax.swing.JPanel();
        jtFichero = new javax.swing.JTextField();
        jbFichero = new javax.swing.JButton();
        pnURLVideo = new javax.swing.JPanel();
        jtURL = new javax.swing.JTextField();
        jDescripcion1 = new javax.swing.JLabel();
        jDescripcion2 = new javax.swing.JLabel();
        jsUmbralSensibilidad = new javax.swing.JSlider();
        jspSizeEscaneo = new javax.swing.JSpinner();
        jlValorSensibilidad = new javax.swing.JLabel();
        pnANPR = new javax.swing.JPanel();
        jDescripcion3 = new javax.swing.JLabel();
        jspSizeMin = new javax.swing.JSpinner();
        jspSizeMax = new javax.swing.JSpinner();
        jDescripcion4 = new javax.swing.JLabel();
        jDescripcion5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        botonDefault = new javax.swing.JButton();

        pnCamara.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos de cámara", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N
        pnCamara.setToolTipText("");

        jlNombre.setText("Nombre:");

        jDescripcion.setText("Descripción:");

        pnFuncionalidadCamara.setBorder(javax.swing.BorderFactory.createTitledBorder("Funcionalidad cámara"));

        gbFuncionalidad.add(jrEntrada);
        jrEntrada.setText("Entrada");

        gbFuncionalidad.add(jrSalida);
        jrSalida.setText("Salida");

        gbFuncionalidad.add(jrAmbas);
        jrAmbas.setText("Entrada y Salida");

        javax.swing.GroupLayout pnFuncionalidadCamaraLayout = new javax.swing.GroupLayout(pnFuncionalidadCamara);
        pnFuncionalidadCamara.setLayout(pnFuncionalidadCamaraLayout);
        pnFuncionalidadCamaraLayout.setHorizontalGroup(
            pnFuncionalidadCamaraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnFuncionalidadCamaraLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnFuncionalidadCamaraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jrEntrada)
                    .addComponent(jrSalida)
                    .addComponent(jrAmbas))
                .addContainerGap(165, Short.MAX_VALUE))
        );
        pnFuncionalidadCamaraLayout.setVerticalGroup(
            pnFuncionalidadCamaraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnFuncionalidadCamaraLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jrEntrada)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jrSalida)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jrAmbas)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtDescripcion.setColumns(20);
        jtDescripcion.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
        jtDescripcion.setRows(5);
        jtDescripcion.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout pnCamaraLayout = new javax.swing.GroupLayout(pnCamara);
        pnCamara.setLayout(pnCamaraLayout);
        pnCamaraLayout.setHorizontalGroup(
            pnCamaraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnCamaraLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnCamaraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtDescripcion)
                    .addComponent(jlNombre)
                    .addComponent(jDescripcion)
                    .addComponent(jtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addComponent(pnFuncionalidadCamara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        pnCamaraLayout.setVerticalGroup(
            pnCamaraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnCamaraLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnCamaraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pnFuncionalidadCamara, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnCamaraLayout.createSequentialGroup()
                        .addComponent(jlNombre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jDescripcion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnMotion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detección de movimiento", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        pnTipoRecurso.setBorder(javax.swing.BorderFactory.createTitledBorder("Fuente de video"));

        gbTipoRecurso.add(jrVideo);
        jrVideo.setText("Fichero de Video");
        jrVideo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrVideoActionPerformed(evt);
            }
        });

        gbTipoRecurso.add(jrURL);
        jrURL.setText("Direccion URL");
        jrURL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrURLActionPerformed(evt);
            }
        });

        pnFicheroVideo.setBorder(javax.swing.BorderFactory.createTitledBorder("Selección de fichero"));

        jbFichero.setText("Seleccionar fichero");
        jbFichero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbFicheroActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnFicheroVideoLayout = new javax.swing.GroupLayout(pnFicheroVideo);
        pnFicheroVideo.setLayout(pnFicheroVideoLayout);
        pnFicheroVideoLayout.setHorizontalGroup(
            pnFicheroVideoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnFicheroVideoLayout.createSequentialGroup()
                .addGroup(pnFicheroVideoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnFicheroVideoLayout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addComponent(jbFichero))
                    .addComponent(jtFichero, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        pnFicheroVideoLayout.setVerticalGroup(
            pnFicheroVideoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnFicheroVideoLayout.createSequentialGroup()
                .addComponent(jtFichero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbFichero)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pnURLVideo.setBorder(javax.swing.BorderFactory.createTitledBorder("URL de la fuente de video"));
        pnURLVideo.setPreferredSize(new java.awt.Dimension(363, 80));

        jtURL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtURLActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnURLVideoLayout = new javax.swing.GroupLayout(pnURLVideo);
        pnURLVideo.setLayout(pnURLVideoLayout);
        pnURLVideoLayout.setHorizontalGroup(
            pnURLVideoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnURLVideoLayout.createSequentialGroup()
                .addComponent(jtURL)
                .addContainerGap())
        );
        pnURLVideoLayout.setVerticalGroup(
            pnURLVideoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnURLVideoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnTipoRecursoLayout = new javax.swing.GroupLayout(pnTipoRecurso);
        pnTipoRecurso.setLayout(pnTipoRecursoLayout);
        pnTipoRecursoLayout.setHorizontalGroup(
            pnTipoRecursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnTipoRecursoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jrVideo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jrURL)
                .addGap(69, 69, 69))
            .addComponent(pnFicheroVideo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnURLVideo, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
        );
        pnTipoRecursoLayout.setVerticalGroup(
            pnTipoRecursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnTipoRecursoLayout.createSequentialGroup()
                .addGroup(pnTipoRecursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrVideo)
                    .addComponent(jrURL))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnFicheroVideo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnURLVideo, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
        );

        jDescripcion1.setText("Tamaño Escaneo:");

        jDescripcion2.setText("Umbral de sensibilidad:");

        jsUmbralSensibilidad.setMaximum(20);
        jsUmbralSensibilidad.setPaintLabels(true);
        jsUmbralSensibilidad.setPaintTicks(true);
        jsUmbralSensibilidad.setValue(10);
        jsUmbralSensibilidad.setValueIsAdjusting(true);
        jsUmbralSensibilidad.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jsUmbralSensibilidadStateChanged(evt);
            }
        });

        jlValorSensibilidad.setText("Valor");

        javax.swing.GroupLayout pnMotionLayout = new javax.swing.GroupLayout(pnMotion);
        pnMotion.setLayout(pnMotionLayout);
        pnMotionLayout.setHorizontalGroup(
            pnMotionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnMotionLayout.createSequentialGroup()
                .addGroup(pnMotionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnMotionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnMotionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDescripcion1)
                            .addComponent(jsUmbralSensibilidad, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jDescripcion2)
                            .addComponent(jspSizeEscaneo, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnMotionLayout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jlValorSensibilidad)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnTipoRecurso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnMotionLayout.setVerticalGroup(
            pnMotionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnMotionLayout.createSequentialGroup()
                .addContainerGap(16, Short.MAX_VALUE)
                .addGroup(pnMotionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnMotionLayout.createSequentialGroup()
                        .addComponent(jDescripcion1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jspSizeEscaneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jDescripcion2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jsUmbralSensibilidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlValorSensibilidad)
                        .addGap(114, 114, 114))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnMotionLayout.createSequentialGroup()
                        .addComponent(pnTipoRecurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        pnANPR.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Reconocimiento de matrículas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        jDescripcion3.setText("Tamaño Minimo y maximo de la matricula:");

        jDescripcion4.setText("Min.");

        jDescripcion5.setText("Max.");

        javax.swing.GroupLayout pnANPRLayout = new javax.swing.GroupLayout(pnANPR);
        pnANPR.setLayout(pnANPRLayout);
        pnANPRLayout.setHorizontalGroup(
            pnANPRLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnANPRLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnANPRLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jDescripcion3)
                    .addGroup(pnANPRLayout.createSequentialGroup()
                        .addComponent(jDescripcion4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jspSizeMin, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jDescripcion5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jspSizeMax, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        pnANPRLayout.setVerticalGroup(
            pnANPRLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnANPRLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jDescripcion3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnANPRLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jspSizeMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jDescripcion4)
                    .addComponent(jspSizeMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jDescripcion5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        botonDefault.setText("Valores por Defecto");
        botonDefault.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botonDefault.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botonDefaultMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addComponent(botonDefault)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(botonDefault)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnMotion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnCamara, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pnANPR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnCamara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(pnMotion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pnANPR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jsUmbralSensibilidadStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jsUmbralSensibilidadStateChanged
        this.refrescarLabelSlider();
    }//GEN-LAST:event_jsUmbralSensibilidadStateChanged

    private void jtURLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtURLActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtURLActionPerformed

    private void jbFicheroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbFicheroActionPerformed
        this.jfFicheroVideo= new JFileChooser();
        int seleccion = jfFicheroVideo.showOpenDialog(this.jtFichero);
        
        if (seleccion == JFileChooser.APPROVE_OPTION){
            this.recusoVideo = jfFicheroVideo.getSelectedFile().toString();  
            jtFichero.setText(recusoVideo);
        }
        
        
        //FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF", "jpg", "gif");
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Sólo algunos formatos de video","mpg");
        this.jfFicheroVideo.setFileFilter(filter);
    }//GEN-LAST:event_jbFicheroActionPerformed

    private void jrURLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrURLActionPerformed
        this.cambiaPanelFuente();
    }//GEN-LAST:event_jrURLActionPerformed

    private void jrVideoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrVideoActionPerformed
        this.cambiaPanelFuente();
    }//GEN-LAST:event_jrVideoActionPerformed

private void botonDefaultMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonDefaultMouseClicked
    this.jspSizeEscaneo.setValue(5);
    this.jspSizeMax.setValue(80);
    this.jspSizeMin.setValue(5);
}//GEN-LAST:event_botonDefaultMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonDefault;
    private javax.swing.ButtonGroup gbFuncionalidad;
    private javax.swing.ButtonGroup gbTipoRecurso;
    private javax.swing.JLabel jDescripcion;
    private javax.swing.JLabel jDescripcion1;
    private javax.swing.JLabel jDescripcion2;
    private javax.swing.JLabel jDescripcion3;
    private javax.swing.JLabel jDescripcion4;
    private javax.swing.JLabel jDescripcion5;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton jbFichero;
    private javax.swing.JFileChooser jfFicheroVideo;
    private javax.swing.JLabel jlNombre;
    private javax.swing.JLabel jlValorSensibilidad;
    private javax.swing.JRadioButton jrAmbas;
    private javax.swing.JRadioButton jrEntrada;
    private javax.swing.JRadioButton jrSalida;
    private javax.swing.JRadioButton jrURL;
    private javax.swing.JRadioButton jrVideo;
    private javax.swing.JSlider jsUmbralSensibilidad;
    private javax.swing.JSpinner jspSizeEscaneo;
    private javax.swing.JSpinner jspSizeMax;
    private javax.swing.JSpinner jspSizeMin;
    private javax.swing.JTextArea jtDescripcion;
    private javax.swing.JTextField jtFichero;
    private javax.swing.JTextField jtNombre;
    private javax.swing.JTextField jtURL;
    private javax.swing.JPanel pnANPR;
    private javax.swing.JPanel pnCamara;
    private javax.swing.JPanel pnFicheroVideo;
    private javax.swing.JPanel pnFuncionalidadCamara;
    private javax.swing.JPanel pnMotion;
    private javax.swing.JPanel pnTipoRecurso;
    private javax.swing.JPanel pnURLVideo;
    // End of variables declaration//GEN-END:variables

    private void setTipoRecurso(TipoRecursoMotion tipo) {
        
        switch(tipo) {
            case URL:
                this.jrURL.setSelected(true);
                this.jrVideo.setSelected(false);
                this.activaOpcionURLVideo();
                break;
            case VIDEO:
                this.jrURL.setSelected(true);
                this.jrVideo.setSelected(false);
                this.activaOpcionFicheroVideo();
                break;
        }
    }

    private void setTipoCamara(TipoCamara tipo) {
        switch(tipo)
        {
//            case BIDIRECCIONAL:
//                this.jrAmbas.setSelected(true);
//                this.jrEntrada.setSelected(false);
//                this.jrSalida.setSelected(false);
//                break;
            case ENTRADA:
                this.jrAmbas.setSelected(false);
                this.jrEntrada.setSelected(true);
                this.jrSalida.setSelected(false);
                break;
            case SALIDA:
                this.jrAmbas.setSelected(false);
                this.jrEntrada.setSelected(false);
                this.jrSalida.setSelected(true);
                break;
        }
    }

    private void setUmbralSensibilidad(int umbral) {
        this.jsUmbralSensibilidad.setValue(umbral);
    }

    public void actualizarPanel(Camara camara) {
        //Asigno valor a los controles
        
        //Valores motion detect    
        this.setRecusoVideo(camara.getConfigdetectionmotion().getDatosRecursos());
        this.jspSizeEscaneo.setValue(camara.getConfigdetectionmotion().getSizeCuadrado());
        this.setTipoRecurso(camara.getConfigdetectionmotion().getTipoRecurso());
        this.setUmbralSensibilidad(camara.getConfigdetectionmotion().getUmbralSensibilidad());
        if(camara.getConfigdetectionmotion().getTipoRecurso()==TipoRecursoMotion.URL){
            jtURL.setText(camara.getConfigdetectionmotion().getDatosRecursos());
        }else{
            jtFichero.setText(camara.getConfigdetectionmotion().getDatosRecursos());
        }
        
        //Valores ANPR
        this.jspSizeMax.setValue(camara.getConfiganpr().getSizeMax());
        this.jspSizeMin.setValue(camara.getConfiganpr().getSizeMin());

        //Valores camara
        this.jtDescripcion.setText(camara.getDescripcion());
        this.jtNombre.setText(camara.getNombre());
        this.setTipoCamara(camara.getTipoCamara());
    }

    private String getRecursosVideo() {
        return this.recusoVideo;
    }

    public void setRecusoVideo(String recusoVideo) {
        this.recusoVideo = recusoVideo;
    }

    private TipoRecursoMotion getTipoRecursoSelecionado() {
        if (this.jrURL.isSelected()) {
            return TipoRecursoMotion.URL;
        } else {
            return TipoRecursoMotion.VIDEO;
        }
    }

    private TipoCamara getTipoCamara() {
        if(this.jrEntrada.isSelected()) {
            return TipoCamara.ENTRADA;
        }else{
            return TipoCamara.SALIDA;
        } 
//        else if (this.jrAmbas.isSelected()) {
//            return TipoCamara.BIDIRECCIONAL;
//        } 
//        else {
//            throw new UnsupportedOperationException();
//        }
    }

    public Camara getEntidadPanel() {
        //Inicializo
        Camara camaraAux = new Camara();
        Configanpr ConfigAnprAux = new Configanpr();
        Configdetectionmotion ConfigMotionAux = new Configdetectionmotion();

        //Recojo datos

        //Recojo Motion
        ConfigMotionAux.setDatosRecursos(this.getRecursosVideo());
        ConfigMotionAux.setSizeCuadrado((Integer) this.jspSizeEscaneo.getValue());
        ConfigMotionAux.setTipoRecurso(this.getTipoRecursoSelecionado());
        ConfigMotionAux.setUmbralSensibilidad(this.jsUmbralSensibilidad.getValue());

        //Recojo ANPR
        ConfigAnprAux.setSizeMax(Integer.valueOf(this.jspSizeMax.getValue().toString()));
        ConfigAnprAux.setSizeMin(Integer.valueOf(this.jspSizeMin.getValue().toString()));

        //Recojo camara
        camaraAux.setActivo(Boolean.FALSE);
        camaraAux.setDescripcion(this.jtDescripcion.getText());
        camaraAux.setNombre(this.jtNombre.getText());
        camaraAux.setTipoCamara(this.getTipoCamara());


        //Retorno valor
        ConfigMotionAux.setCamara(camaraAux);
        ConfigAnprAux.setCamara(camaraAux);
        camaraAux.setConfiganpr(ConfigAnprAux);
        camaraAux.setConfigdetectionmotion(ConfigMotionAux);

        return camaraAux;
    }

    public void borrarTodo() {
        this.limpiarGrupoTipoCamara();
        this.limpiarGrupoTipoFuente();
        this.gbFuncionalidad.clearSelection();
        this.gbTipoRecurso.clearSelection();
        this.jtNombre.setText("");
        this.jtDescripcion.setText("");
        this.jspSizeEscaneo.setValue(0);
        this.jtFichero.setText("");
        this.jtURL.setText("");
        this.jsUmbralSensibilidad.setValue(Math.round(this.jsUmbralSensibilidad.getMaximum() / 2)); //lo asigno en el centro
        this.refrescarLabelSlider();
        this.jspSizeMax.setValue(0);
        this.jspSizeMin.setValue(0);
        //Restablezco el valor de

        this.updateUI();
        this.repaint();

    }

    public void refrescarLabelSlider() {
        String valor = ((Integer) this.jsUmbralSensibilidad.getValue()).toString();
        this.jlValorSensibilidad.setText(valor);
    }

    private void cambiaPanelFuente() {
        this.jtFichero.setText("");
        this.jtURL.setText("");
        this.activarDesactivarPanelFuente();
    }
    private void activarDesactivarPanelFuente()
    {        
        this.pnURLVideo.setEnabled(false);
        this.pnFicheroVideo.setEnabled(false);

        if (this.jrVideo.isSelected()) {

            this.pnFicheroVideo.setEnabled(true);

        } else {
            if (this.jrURL.isSelected()) {
                this.pnURLVideo.setEnabled(true);
            }
        }
    }

    private void activaOpcionURLVideo() {
        this.jrURL.setSelected(true);
        this.jrVideo.setSelected(false);
        this.activarDesactivarPanelFuente();
    }

    private void activaOpcionFicheroVideo() {
        this.jrURL.setSelected(false);
        this.jrVideo.setSelected(true);
        this.activarDesactivarPanelFuente();
    }

    private void limpiarGrupoTipoCamara() {
        this.jrAmbas.setSelected(false);
        this.jrEntrada.setSelected(false);
        this.jrSalida.setSelected(false);
    }

    private void limpiarGrupoTipoFuente() {
        this.jrURL.setSelected(false);
        this.jrVideo.setSelected(true);
        this.activarDesactivarPanelFuente();
    }
}
